package 基础篇.阻塞线程;

/**
 * Created by Administrator on 2018/7/28 0028.
 */
public class YieldThread implements Runnable{
    public static void main(String[] args) {
        YieldThread r1=new YieldThread();
        Thread t1=new Thread(r1,"t1");
        t1.setPriority(Thread.MAX_PRIORITY);
        t1.start();
        Thread t2=new Thread(r1,"t2");
        t2.setPriority(Thread.MIN_PRIORITY);
        t2.start();
    }

    @Override
    public void run() {
        for(int i=0;i<100;i++){
            if(i==20){
                Thread.yield();
            }
            System.out.println(Thread.currentThread().getName()+" "+i);
        }
    }
}
